package com.fyzk.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

public class SoundPoolUtils {

	private static SoundPoolUtils soundPoolUtils;
	private static SoundPool soundPool;
	private static int streamID;
	
	public static SoundPoolUtils getSoundPool(){
		if (soundPoolUtils == null) {
			soundPoolUtils = new SoundPoolUtils();
		}
		return soundPoolUtils;
	}
	
	/**
	 * 播放声音
	 * @param context
	 * @param resId		声音资源id
	 * @param loop		是否循环（0：不循环；-1：循环）
	 */
	public void playSound(Context context, int resId, int loop){
		if (soundPool == null) {
			soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
		}
		soundPool.load(context, resId, 1);
		streamID = soundPool.play(1, 1, 1, 0, loop, 1);
	}
	
	public void stopSound(){
		soundPool.stop(streamID);
	}
}
